package com.qtenv.datasync.worker.degao;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.qtenv.datasync.api.degao.DeGaoApi;
import com.qtenv.datasync.base.ArchiveSyncer;
import com.qtenv.datasync.constant.AppConstants;
import com.qtenv.datasync.service.entity.Terminals_bf;
import com.qtenv.datasync.service.entity.degao.DGTerminals;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName DGArchiveSyncWorker
 * @Author CBL
 * @Date 2022/3/17 9:01
 **/
@Component
public class DGArchiveSyncWorker extends ArchiveSyncer {
    public DGArchiveSyncWorker() {
        super("德高");
    }

    @Override
    public List<Terminals_bf> getTerminals() {
        String terminalData = DeGaoApi.GetAllScadaListForRealTime(AppConstants.DG_TYPE, AppConstants.DG_REGION_CODE);
        List<Terminals_bf> terminals = this.transform(terminalData);
//        System.out.println(JSON.toJSONString(terminals, true));
//        terminals.removeIf(t -> !(t.getTerminalID().equals("9112")));

        System.out.println("从厂家【" + this.getSupplier() + "】获取【档案】数量：" + terminals.size());
        return terminals;
    }

    private List<Terminals_bf> transform(String terminalData) {
        List<Terminals_bf> result = CollectionUtil.newArrayList();

        List<DGTerminals> dgTerminalsList = JSON.parseArray(terminalData, DGTerminals.class);
        dgTerminalsList.forEach(dgTerminals -> {
            Terminals_bf terminals = new Terminals_bf();
            BeanUtil.copyProperties(dgTerminals, terminals);
            terminals.setTenant_id(AppConstants.APP_TENANT_ID);
            terminals.setSupplierID(AppConstants.DG_SUPPLIER_ID);
            terminals.setTerminalMark(1);
            terminals.setUserArea(AppConstants.APP_TENANT_ID);

            result.add(terminals);
        });

        return result;
    }

    public static void main(String[] args) {
        DGArchiveSyncWorker worker = new DGArchiveSyncWorker();
        System.out.println(JSON.toJSONString(worker.getTerminals(), true));
//        worker.syncTerminals();
    }
}
